package com.zjsru.product.mapper;

import com.zjsru.product.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ProductMapper {

    @Insert("insert into product(product_name,product_description,product_price,product_stock,create_time,update_time)values (#{productName},#{productDescription},#{productPrice},#{productStock},#{createTime},#{updateTime})")
    void createCategory(Product product);

    @Delete("delete from product where product_id=#{productId}")
    void deleteCategory(@Param("productId") Integer productId);

    @Select("select * from product where product_name like concat('%',#{productName},'%')")
    List<Product> searchCategoryByName(@Param("productName") String productName);

    @Select("select * from product")
    List<Product> searchCategory();

    void updateCategory(Product product);

    @Update("update product set product_stock = product_stock + #{integer},update_time = #{now} where product_id = #{productId}")
    void addProductCount(@Param("integer") Integer integer,@Param("productId") Long productId,@Param("now") LocalDateTime now);

    @Select("select * from product where product_id = #{productId}")
    Product queryProductById(@Param("productId") Long productId);

    @Select("select product_stock from product where product_id = #{productId}")
    Integer searchProductNum(@Param("productId") Long productId);
}